package com.ruoyi.goods.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.goods.domain.WGoodsExt;
import com.ruoyi.goods.service.IWGoodsExtService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 建材扩展Controller
 * 
 * @author wzy
 * @date 2024-05-28 09:21:33
 */
@RestController
@RequestMapping("/goods/gbmdext")
public class WGoodsExtController extends BaseController
{
    @Autowired
    private IWGoodsExtService wGoodsExtService;

    /**
     * 查询建材扩展列表
     */
    @PreAuthorize("@ss.hasPermi('goods:gbmdext:list')")
    @GetMapping("/list")
    public TableDataInfo list(WGoodsExt wGoodsExt)
    {
        startPage();
        List<WGoodsExt> list = wGoodsExtService.selectWGoodsExtList(wGoodsExt);
        return getDataTable(list);
    }

    /**
     * 导出建材扩展列表
     */
    @PreAuthorize("@ss.hasPermi('goods:gbmdext:export')")
    @Log(title = "建材扩展", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WGoodsExt wGoodsExt)
    {
        List<WGoodsExt> list = wGoodsExtService.selectWGoodsExtList(wGoodsExt);
        ExcelUtil<WGoodsExt> util = new ExcelUtil<WGoodsExt>(WGoodsExt.class);
        util.exportExcel(response, list, "建材扩展数据");
    }

    /**
     * 获取建材扩展详细信息
     */
    @PreAuthorize("@ss.hasPermi('goods:gbmdext:query')")
    @GetMapping(value = "/{goodsExtId}")
    public AjaxResult getInfo(@PathVariable("goodsExtId") Long goodsExtId)
    {
        return success(wGoodsExtService.selectWGoodsExtByGoodsExtId(goodsExtId));
    }

    /**
     * 新增建材扩展
     */
    @PreAuthorize("@ss.hasPermi('goods:gbmdext:add')")
    @Log(title = "建材扩展", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WGoodsExt wGoodsExt)
    {
        wGoodsExt.setCreateBy(getNickName());
        return toAjax(wGoodsExtService.insertWGoodsExt(wGoodsExt));
    }

    /**
     * 修改建材扩展
     */
    @PreAuthorize("@ss.hasPermi('goods:gbmdext:edit')")
    @Log(title = "建材扩展", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WGoodsExt wGoodsExt)
    {
        wGoodsExt.setUpdateBy(getNickName());
        return toAjax(wGoodsExtService.updateWGoodsExt(wGoodsExt));
    }

    /**
     * 删除建材扩展
     */
    @PreAuthorize("@ss.hasPermi('goods:gbmdext:remove')")
    @Log(title = "建材扩展", businessType = BusinessType.DELETE)
	@DeleteMapping("/{goodsExtIds}")
    public AjaxResult remove(@PathVariable Long[] goodsExtIds)
    {
        return toAjax(wGoodsExtService.deleteWGoodsExtByGoodsExtIds(goodsExtIds));
    }

    /**
     * 查询建材扩展字典项
     */
//    @PreAuthorize("@ss.hasPermi('goods:gbmdext:list')")
    @GetMapping("/listoption")
    public AjaxResult listoption(WGoodsExt wGoodsExt)
    {
        return success(wGoodsExtService.selectWGoodsExtList(wGoodsExt));
    }

}
